#![allow(unused)]

pub mod base;
pub mod biz;
pub mod service;

use tracing::info;

/*
mnemonic: "spread radio stool immune coin amount lonely uphold usual worry bone student",
*/
pub async fn test_coin(env: &str) -> anyhow::Result<()> {
    let client = base::client::build_client(env);
    let payer_pr = "e929e6855f0b236ea0c653d9851c4963e81990edc0f4565d2f4b9806950992b6";
    let payer_addr_bs58 = "TAfcpSGbvCEuch4MMPXooVEaPJ7sAVQqB2";
    let payer_addr = "07a48510445C4D33C95bF1B9859BA0F9D6941668";
    let payer_addr = "41".to_string() + payer_addr;
    let user_pr = "b35e0ff582e16a8f2e6f8acd334f2229c87dc23ce0b33423c735c969228d92a6";
    let user_addr_bs58 = "TEr89ptiujjR93h5wfvmMRNQbwnzYL6wp2";
    let user_addr = "413581ab69BE6854C52C4E7339170D771C8BBBA5E2";
    let number = 1_000_000; // 1trx=10^6 sun
                            // let contract = "0x43d58716134eE123B9523A4e1c1F0C6F2c2EaFf0";

    // balance
    // let account = client.get_account(payer_addr).await?;
    // info!("account: {:?}", account.balance);
    // transfer coin
    let hash =
        service::coin::transfer_coin(&client, payer_pr, payer_addr.as_str(), user_addr, number)
            .await?;
    info!("hash: {}", hash);
    // approve
    Ok(())
}

pub async fn test_token(env: &str) -> anyhow::Result<()> {
    let client = base::client::build_client(env);
    let payer_pr = "e929e6855f0b236ea0c653d9851c4963e81990edc0f4565d2f4b9806950992b6";
    let payer_addr_bs58 = "TAfcpSGbvCEuch4MMPXooVEaPJ7sAVQqB2";
    let payer_addr = "4107a48510445C4D33C95bF1B9859BA0F9D6941668";
    let contract_bs58 = "TXLAQ63Xg1NAzckPwKHvzw7CSEmLMEqcdj";
    let user_addr = "413581ab69BE6854C52C4E7339170D771C8BBBA5E2";
    let user_addr_bs58 = "TEr89ptiujjR93h5wfvmMRNQbwnzYL6wp2";
    let user_pr = "b35e0ff582e16a8f2e6f8acd334f2229c87dc23ce0b33423c735c969228d92a6";
    let to_pr = "3ab2bed8bcd2df4c3bdc0a41ee070ba2436b079260a1b48cfc6ea2c337097135";
    let to_addr = "414f5beaba852cae03febbb992444bbb1dd5156f58";
    let to_addr_bs58 = "THCpViGgBfwRoPr37RWTY93rLkq7wPRkNP";
    let number = "1000000"; // 1trx=10^6 sun

    // balance
    // let bal = client.token_balance(payer_addr_bs58, contract_bs58).await?;
    // info!("bal: {}", bal);

    // let hash = service::wallet::transfer_token(&client, contract_bs58, payer_pr, payer_addr_bs58, user_addr_bs58, number).await?;
    // info!("hash: {}", hash);

    // let hash = service::wallet::approve_token(&client, contract_bs58, user_pr, user_addr_bs58, payer_pr, payer_addr_bs58, number).await?;
    // info!("hash: {}", hash);
    // let allowance = service::token::allowance_token(&client, user_addr_bs58, payer_addr_bs58, contract_bs58).await?;
    // info!("allowance: {}", allowance);

    // let hash = service::token::transfer_from_token(&client, contract_bs58, payer_pr, payer_addr_bs58, user_addr_bs58, to_addr_bs58, number).await?;
    // info!("hash: {}", hash);

    let hash = biz::collect::token_collect(
        &client,
        contract_bs58,
        user_pr,
        payer_pr,
        to_addr_bs58,
        number,
    )
    .await?;
    info!("hash: {}", hash);

    Ok(())
}
